#include <stdio.h>
#include <memory.h>
#if 0
#include "sort.hpp"
#else

/* Sorts an array of elements in the range [first, last) according to their
 * hash value mapped by the function 'hash', and stores the results in a 
 * separate array 'dest'. The sorting algorithm is stable.
 */
template <class FwdIt, class RanIt, class Func>
void insertion_sort(FwdIt first, FwdIt last, RanIt dest, Func hash)
{
    if (first == last)
        return;

    *dest = *first;
    size_t i = 1;
    for (FwdIt it = first; ++it != last; i++)
    {
        size_t k = hash(*it);
        size_t hole = i;
        while (hole > 0 && hash(dest[hole-1]) > k)
            hole--;

        for (size_t j = i; j > hole; j--)
            dest[j] = dest[j - 1];
        dest[hole] = *it;
    }
}

/* Sorts an array of elements in the range [first, last) according to their
 * hash value mapped by the function 'hash', and stores the results in a
 * separate array 'dest'. The hash value must be an unsigned integer in the
 * range [0, ValueSize). The number of elements with each hash value is stored
 * in the array 'count'. This sorting algorithm is stable.
 */
template <size_t ValueSize, class FwdIt, class RanIt, class size_type, class Func>
void stable_counting_sort(
    FwdIt first,
    FwdIt last,
    RanIt dest,
    size_type count[ValueSize], 
    Func hash, 
    bool zeroed = false)
{
    typedef size_t key_type;
    
    if (!zeroed)
        memset(count, 0, sizeof(size_type) * ValueSize);

    size_type n = 0;
    for (FwdIt it = first; it != last; ++it, ++n)
    {
        key_type k = hash(*it);
        ++count[k];
    }

    /* Use insertion sort when there are only a few elements. */
    if (n <= 4)
    {
        insertion_sort(first, last, dest, hash);
        return;
    }

    size_type start[ValueSize];
    size_type index = n;
    for (key_type k = ValueSize; k > 0; )
    {
        --k;
        start[k] = (index -= count[k]);
    }

    for (FwdIt it = first; it != last; ++it)
    {
        key_type k = hash(*it);
        dest[start[k]++] = *it;
    }
}
#endif

#if 1
struct Password
{
    int value;
    Password() { }
    Password(const char s[5])
    {
#define ZERO_16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        static const unsigned char map[256] = {
            ZERO_16, ZERO_16, ZERO_16, 
             0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  0,  0,  0,  0,  0,  0,
             0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
            25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,  0,  0,  0,  0,  0,
             0, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
            51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61
        };
        value = 0;
        for (int i = 0; i < 5; i++)
            value |= (int)map[(unsigned char)s[i]] << (i * 6);
    }
    size_t operator[](size_t pos) const { return (value >> (pos*6)) & 0x3F; }
};

struct PasswordExtractor
{
    size_t k; /* extract which pos */
    PasswordExtractor(size_t pos) : k(pos) { }
    size_t operator()(Password p) const { return p[k]; }
};
#else
struct Password
{
    char value[6];
    Password() { }
    Password(const char s[5]) { memcpy(value, s, 5); value[5] = 0; }
    size_t operator[](size_t pos) const 
    {
        char c = value[pos];
        int pc = (c >= 'A' && c <= 'Z')? c - 'A' + 10 :
                 (c >= 'a' && c <= 'z')? c - 'a' + 36 : c - '0';
        return pc;
    }
};

struct PasswordExtractor
{
    size_t k; /* extract which pos */
    PasswordExtractor(size_t pos) : k(pos) { }
    size_t operator()(const Password &p) const { return p[k]; }
};
#endif

static Password g_passwords[50000];
static long long share[6];      /* number of pairs that share k positions */

typedef unsigned int count_t;
static count_t counter[6][64];  /* counter cache for each recursion level */

/* Count the number of pairs that share the k-th char, 0 <= k <= 4. */
static void check_each_position(
    Password passwords[], count_t n, 
    size_t num_chosen, size_t start_pos)
{
    static Password tmp[50000];
    
    ++num_chosen;
    for (size_t pos = start_pos; pos < 5; pos++)
    {
        count_t *count = counter[num_chosen];
        stable_counting_sort<64>(passwords, passwords + n, tmp, count,
                                 PasswordExtractor(pos), true);
        memcpy(passwords, tmp, sizeof(Password)*n);

        for (count_t i = 0; i < n; )
        {
            size_t k = passwords[i][pos];
            count_t num = count[k];
            if (num > 1)
            {
                share[num_chosen] += num * (num - 1) / 2;
                check_each_position(passwords + i, num, num_chosen, pos + 1);
            }
            i += num;
            count[k] = 0;
        }
    }
}

static int solve()
{
    int n = 0;
    char line[10];

    /* Skip blank lines and read the number of passwords. */
    while (fgets(line, sizeof(line), stdin))
    {
        if (sscanf(line, "%d", &n) == 1)
            break;
    }
    if (n == 0)
        return 0;

    /* Read passwords and convert each to a 30-bit integer. */
    for (int i = 0; i < n; i++)
    {
        fgets(line, sizeof(line), stdin);
        g_passwords[i] = Password(line);
    }

    /* Check each position recursively. */
    memset(share, 0, sizeof(share));
    memset(counter, 0, sizeof(counter));
    check_each_position(g_passwords, n, 0, 0);

    /* Update the sharing count by removing duplicates. */
    share[4] -=  5*share[5];
    share[3] -= 10*share[5] + 4*share[4];
    share[2] -= 10*share[5] + 6*share[4] + 3*share[3];
    share[1] -=  5*share[5] + 4*share[4] + 3*share[3] + 2*share[2];
    share[0] = (long long)n*(n-1)/2 - 
        (share[1]+share[2]+share[3]+share[4]+share[5]);

#if 1
    printf("%d", (int)share[5]);
    for (int k = 4; k >= 0; k--)
        printf(" %d", (int)share[k]);
    printf("\n");
#endif
    return 1;
}

int main()
{
#if 0
    freopen("input/4018_ext.txt", "r", stdin);
    while (solve());
#else
    while (solve());
#endif
    return 0;
}
